programming4us
           
 
 
Windows

SOA with .NET and Windows Azure : Microsoft Messaging Queue (MSMQ)

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
12/5/2010 11:55:39 AM
MSMQ was introduced as part of Windows NT 4.0. It established intermediary messaging queues that enabled reliability and scalability. An MSMQ implementation was typically comprised of three major components:
  • sending application– The sending application prepared the message and placed it into the queue.

  • message queues (storage)– The message was persisted in the message store.

  • receiving application– The receiving application retrieved the message from the queue and processed it. Alternatively, MSMQ notified an application when a message was received.

As shown in Figure 1, the application sending the message and the application receiving the message were not tightly coupled. If the receiving application was offline, all messages were persisted. Once the receiving application was back online, messages were automatically retrieved and processed. This significantly increased the reliability of messaging-based applications.

Figure 1. Messaging with MSMQ consisted of a sending application, message queue and receiving application.


The Queues

Message storage in MSMQ was simply referred to as the “queues.” MSMQ supported two types of queues:

  • private (local to a machine)

  • public (published in the Active Directory and available across the enterprise)

Applications running on different servers throughout the network could find and use public queues via the Active Directory.

The original MSMQ implementation introduced had a complex programming model and had to be accessed via a COM interface. .NET later simplified MSMQ by introducing the System.Messaging namespace, which contained several classes, including Message and MessageQueue. The Message class was used to create and use messages, whereas the MessageQueue class contained functionality to work with and manipulate MSMQ queues.

MSMQ was not installed by default and had to be enabled on the server. Queues could be created programmatically or manually using the MMC console. Programmatically, queues were generated by using the Create() method in the MessageQueue class. The code in the following example could be used to create a private queue on a local machine:

Example 1.
string queuePath = @".\private$\NewQueue";
MessageQueue MessageQ;
if (MessageQueue.Exists(queuePath))
MessageQ = new MessageQueue(queuePath);
else
MessageQ = MessageQueue.Create(queuePath);

The Create() method must be provided for the location and name of the queue. In Example 1, the single dot (.) and the keyword Private$ indicates that the queue is being created on the local machine.

The syntax for creating a public queue is:

MachineName\QueueName.

Queues could be deleted via the MMC or by invoking the Delete() method in the MessageQueue class, as shown here:

Example 2.
MessageQueue MessageQ;
MessageQ.Delete(".\Private$\NewQueue")

Sending and Receiving Messages

The Send method of the MessageQueue class was used by the sending application to post a message to a queue, as follows:

Example 3.
MessageQueue MessageQ;
Message Message;
MessageQ = new MessageQueue(".\Private$\NewQueue");
Message = new Message("This is a message");
MessageQ.Send(Message);

The send method took an object as the first parameter to denote the message body. The argument could be a Message object or any other object. If the object was not of type Message, it was serialized and stored in the message body.

Serializing objects across process and machine boundaries was not new at the time and had already been supported by .NET Remoting, DCOM, and Web services. MSMQ, however, provided the ability to deliver objects asynchronously and reliably so that they could survive server crashes and reboots. The messages could, in effect, persist indefinitely until they were retrieved and consumed. To transfer objects, MSMQ required a formatter to be specified.

Three formatters were provided:

  • ActiveXMessageFormatter (used to serialize ActiveX objects)

  • BinaryMessageFormatter (serialized objects using binary serialization)

  • XMLMessageFormatter (used XML to serialize messages)

The MessageQueue class contained two methods that supported reading a message from a queue:

  • Receive

  • Peek

The Receive method resulted in removing a message from the queue. (The Peek method was similar, but the message was not actually removed.)

Provided here is an example demonstrating the Receive method:

Example 4.
string queuePath = @".\private$\NewQueue";
MessageQueue MessageQ;
Message message;
MessageQ = new MessageQueue(queuePath);
message = MessageQ.Receive;

The Receive method would indefinitely block processing. However, the class contained several overloads, one of which took in the TimeSpan argument that allowed an exception to be generated if a message was not returned in a specified time span.

In this example, the TimeSpan has been set to 1 second:

Example 5.
message = MessageQ.Receive(New TimeSpan(1000));

The Peek and Receive methods were synchronous in nature and could be invoked asynchronously by using the methods BeginPeek() and EndPeek() or BeginReceive() or EndReceive().


Other -----------------
- Windows 7 : Working at the Command Line (part 3)
- Windows 7 : Working at the Command Line (part 2)
- Windows 7 : Working at the Command Line (part 1)
- Windows 7 : Getting to the Command Line (part 2) - Running CMD
- Windows 7 : Getting to the Command Line (part 1)
- Windows Azure : Programming Access Control Service (part 10) - Deploying the Web Service in Windows Azure
- Windows Azure : Programming Access Control Service (part 9) - Configuring a Web Service Client to Acquire and Send SAML Tokens
- Windows Azure : Programming Access Control Service (part 8)
- Windows Azure : Programming Access Control Service (part 7) - Integrating ACS with a SAML Token Provider
- Windows Azure : Programming Access Control Service (part 6)
- Windows Azure : Programming Access Control Service (part 5)
- Windows Azure : Programming Access Control Service (part 4)
- Windows Azure : Programming Access Control Service (part 3)
- Windows Azure : Programming Access Control Service (part 2)
- Windows Azure : Programming Access Control Service (part 1)
- Windows 7 : Working with Registry Entries (part 3)
- Windows 7 : Working with Registry Entries (part 2)
- Windows 7 : Working with Registry Entries (part 1) - Changing the Value of a Registry Entry
- Windows 7 : Keeping the Registry Safe
- Windows 7 : Getting to Know the Registry (part 2)
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us